package com.ruoyi.web.controller.comprehensive;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.pengjie.SnowflakeIdUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.comprehensive.domain.Prevention;
import com.ruoyi.comprehensive.dto.PreventionDto;
import com.ruoyi.comprehensive.service.IPreventionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 通防填报管理Controller
 * 
 * @author hcc
 * @date 2023-12-16
 */
@RestController
@RequestMapping("/comprehensive/measures")
public class PreventionController extends BaseController
{
    @Autowired
    private IPreventionService preventionService;

    /**
     * 查询通防填报管理列表
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:measures:list')")
    @GetMapping("/list")
    public TableDataInfo list(Prevention prevention)
    {
        startPage();
        List<Prevention> list = preventionService.selectPreventionList(prevention);
        return getDataTable(list);
    }

    /**
     * 导出通防填报管理列表
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:measures:export')")
    @Log(title = "通防填报管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Prevention prevention)
    {
        List<Prevention> list = preventionService.selectPreventionList(prevention);
        ExcelUtil<Prevention> util = new ExcelUtil<Prevention>(Prevention.class);
        util.exportExcel(response, list, "通防填报管理数据");
    }

    /**
     * 获取通防填报管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:measures:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(preventionService.selectPreventionById(id));
    }

    /**
     * 新增通防填报管理
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:measures:add')")
    @Log(title = "通防填报管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Prevention prevention)
    {
        prevention.setId(String.valueOf(new SnowflakeIdUtils(5,8).nextId()));
        return toAjax(preventionService.insertPrevention(prevention));
    }

    /**
     * 修改通防填报管理
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:measures:edit')")
    @Log(title = "通防填报管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Prevention prevention)
    {
        return toAjax(preventionService.updatePrevention(prevention));
    }

    /**
     * 删除通防填报管理
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:measures:remove')")
    @Log(title = "通防填报管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(preventionService.deletePreventionByIds(ids));
    }
    /**
     * 查询通防填报管理列表
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:measures:list')")
    @GetMapping("/getList")
    public TableDataInfo getList(Prevention prevention) {
        startPage();
        List<PreventionDto> list = preventionService.getPreventionList(prevention);
        return getDataTable(list);
    }
    /**
     * 获取通防填报管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:measures:query')")
    @GetMapping("/getPreventionById/{id}")
    public AjaxResult getPreventionById(@PathVariable("id") String id) {
        PreventionDto preventionDto = preventionService.getPreventionById(id);
        return success(preventionDto);
    }
}
